package com.biz.primus.ms.commodity.trans;

import com.biz.primus.ms.commodity.dao.po.ProductCascade;
import com.biz.primus.ms.commodity.dao.po.ProductCascadeItem;
import com.biz.primus.ms.commodity.dao.ro.ProductCascadeRo;
import com.google.common.base.Function;
import com.google.common.collect.Lists;
import org.apache.commons.lang3.StringUtils;

import java.util.List;

/**
 * 转换器(ProductCascade --> ProductCascadeRo)
 *
 * @author david-liu
 * @date 2017年02月16日
 * @reviewer
 */
public class ProductCascade2ProductCascadeRo implements Function<ProductCascade, ProductCascadeRo> {
    @Override
    public ProductCascadeRo apply(ProductCascade input) {
        ProductCascadeRo resp = new ProductCascadeRo();
        final List<ProductCascadeItem> items = input.getItems();
        List<Long> itemIds = Lists.newArrayList();
        for (ProductCascadeItem item: items) {
            itemIds.add(item.getId());
        }
        resp.setProductCascadeId(input.getGlProduct().getId());
        resp.setId(input.getId());
        resp.setValue(input.getValue());
        resp.setCascadeItemIds(StringUtils.join(itemIds, ","));
        resp.setUpdateTimestamp(input.getUpdateTimestamp());
        resp.setCreateTimestamp(input.getCreateTimestamp());
        return resp;
    }
}
